package web.servlet.old;

/**
 * @Author:fhx
 * @Date:2024/4/19
 * @Project:BrandWork
 */
import com.alibaba.fastjson.JSON;
import pojo.Brand;
import service.BrandService;

import java.io.BufferedReader;
import java.io.IOException;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import service.impl.BrandServiceImpl;

public class AddServlet extends HttpServlet {
    private BrandService brandService = new BrandServiceImpl();

    public AddServlet() {
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        BufferedReader br = request.getReader();
        String params = br.readLine();
        Brand brand = (Brand)JSON.parseObject(params, Brand.class);
        this.brandService.add(brand);
        response.getWriter().write("success");
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
